Assembly Reference Guide

                                                                      

---===Reference Guide===---                                             

---===To Assembly Language===---                   

by: ProZaq                               

--==< Intro >==--

Wanna be a hacker? Wanna crack? Gotta know assembly! ‘Cause it’s assembly that makes the world go round! Yes it’s ugly...Yes it makes you wanna puke...But if you know this you can sit your butt down to any machine and have your way on it! This file WILL NOT deal with how to write assembly code. It’s a brief explanation of common addressing modes and instructions. It’s intended to help you to figure out what’s going on in the code, if you’re for example stuck on the following command: “move.l  (A7)+,4(A7,D0.l)”. You will be able to look up exactly what the hell this line executes. I know from personal experience that the toughest part in cracking a program is to follow the code through, and understanding what’s going on. So that’s what this file will help you with! Therefore, this file is NOT a TUTORIAL but more of a quick and efficient REFERENCE GUIDE for those who still haven’t fully gotten the hang of all the different assembly addressing modes and instructions.

--==< Addressing Modes >==--

- Data register direct addressing:

   add.b

    D0,D1

   : adds the value in D0 to D1

- Address register direct addressing:

   add.l

     D0,A1

    : adds value D0 to A1

- Address register indirect addressing:

   move.l

   (A1),D7

  : moves contents of address to data register 
  e.g. if A1 contained $1111, and the address $1111 contains 00001234 then after the operation 00001234 would be loaded in data register 7 (D7).

   move.l

  D7,(A1)

   : moves number value of D7 into the location pointed to by A1.

- Address register indirect with post increment:

   move.l

   D7,(A1)+

 : moves the long in D7 to memory location in A1 then adds 4 to A1 (because the data item was a long). With other words after the move, it increments the address register by the size of the data

  
move.l

(A0)+,(A1)+
: moves four bites from memory location in A0 to memory location in A1 then adds four to A0 and A1

- Address register indirect addressing with pre decrement:

   move.b

   D0, -(A1)

   : decrement A1 by one (because it’s a byte) then move word in D0 to the address held in A1
(When bytes are moved onto the STACK then the stack pointer changes by 2 because words and longs have to be moved to even addresses)

- Address register indirect addressing with displacement:

   move.w

  D0,4(A1)

   : move word in D0 to the memory location in A1+4.
  e.g. if D0 consists of 01 and A1 contains $1000 then 01 will be moved to address $1004

  move.l

-2(A1),D0

: moves long at A1-2 to D0
(offset has to be a 16 bit word- max value=32768, min value -32767)

- Address register indirect addressing with index:

  
move.w

  69(A1,D0.l),D1

  : 
moves data word from address A1+D0+69 to D1.
(displacement must fit in a byte, >-127, <128)

- Absolute short addressing:

   move.w

69,D0

   : moves word at ADDRESS 69 to D0

- Immediate mode addressing:

   move.w

  #69,D0

   : move NUMBER 69 into D0

- Absolute long addressing:

   move.w

  D0,$69000

  : moves word from D0 to address $69000

- Program counter addressing with displacement:

   move.w

12(pc),D0

   : move word 12 bytes from current location to D0

- Program counter addressing with index:

   move.l

   69(pc,D0.l),D1

  : move data from 69+ current location + D0.l into D1
(displacement must fit into a byte)

- Status register addressing:

  move.w

   #69,sr

   : move number 69 into status register
(to use status register a WORD needs to be moved)

   move.b

   #0,ccr

   : move 0 to condition code register

--==< Instructions >==--

Arithmetic Instructions:
 - ADD - Adds two operands. One operand must be a data register. 
 - ADDA - Adds an operand to an address register. 
 - ADDI - Adds a real number to an operand.  
 - ADDQ - Adds a number between zero and eight to an operand. 
 - ADDX - Allows adding of numbers of any length. 
 - SUB - Subtracts source operand from destination operand.
 - SUBA - Subtracts the source operand from an address register. 
 - SUBI - Subtracts a real number from the destination operand. 
 - SUBQ - Subtracts a number between zero and eight from a destination operand.  
 - SUBX - Allows subtraction of numbers of any length- CLR - Clears an operand. 
 - MULS - Multiplies destination operand by source operand using signed arithmetic. 
 - MULU - Multiplies destination operand by source operand using unsigned arithmetic
 - DIVS - Divides destination operand by source operand using signed arithmetic.  
 - DIVU - Divides destination operand by source operand using unsigned arithmetic. 
 - NEG - Negates a number.
 - CMP - Compares two operands and sets condition code flags.  
 - CMPA - Compares an operand to an address register then sets the condition code flags. 
 - CMPI - Compares a real number to an operand then sets the condition flags. 
 - CMPM - Compares contents of two memory locations using post increment addressing mode. 
 - TAS - Test a byte and sets the high order bit. 
 - TST - Tests an operand - compares it to zero.
 - EXT - Sign extend a byte or word to word or long respectively.

Program Control Instructions:  
 - Bcc - Branch if a condition (cc) is met.  
  Different conditions (cc) for Branch:

   BCC - branch if the carry bit is clear. (a zero)

   BCS - branch if the carry bit is set. (a one) 

   
BEQ - branch if equal. 

   BGE - Branch if greater than or equal. 

   BGT - Branch if greater than. 

   BHI - Branch if higher than. Used on unsigned numbers. 

   BLE - Branch if less than or equal. 

   BLS - Branch if lower than or the same. Used on unsigned numbers. 

   BLT - Branch if less than. 

   BMI - Branch if minus. 

   BNE - Branch if not equal. 

   BPL - Branch if plus. 

   BVC - Branch if the V bit is clear. (no overflow)

   BVS - Branch if the V bit is set. (overflow) 

   BRA - Always branch. 
 - DBcc - Decrement then branch if condition is met. 
 - Scc - Set if condition is met.  
 - BSR - Branch to subroutine.  
 - JSR - Jump to subroutine.  
 - RTS - Return from subroutine.  
 - JMP - Jump to an absolute memory location. 
 - RTR - Restores the program counter and condition codes from the stack.  

Logical Operation Instructions:
 - AND - Does AND operation with the operands.  
 - ANDI - Does AND operation with a real number and an operand.  
 - OR - Does OR operation with the operands.
 - ORI - Does OR with a real number and an operand.  
 - EOR - Does Exclusive OR with two operands. 
 - EORI - Does Exclusive OR with operand and a real number.
 - NOT - Inverts an operand.    

Data Movement Instructions: 
 - EXG - Exchange contents of two registers. 
 - LEA - Load Effective Address. Calculate a memory address and store it in an address register.  
 - LINK - Allocates a stack frame.  
 - MOVE - Move source operand into destination operand. 
 - MOVEM - Transfers multiple register to and from memory. 
 - MOVEP - Transfers data to and from an eight bit peripheral. 
 - MOVEQ - Loads a data register with a number in the range of +- 128. 
 - PEA - Same as LEA, but pushes the address onto the stack. 
 - SWAP - Swaps the words of a data register. The high word becomes the low and the low the high. 
 - UNLK - Unallocates a stack frame.    

Shifting and Rotating Instructions:
 - ASL and ASR - Arithmetic shift left or right.  
 - LSL and LSR - Logical shift left or right.  
 - ROL and ROR - Rotate left or right. 
 - ROXL and ROXR - Rotate with the carry bit left or right.   

Bit Manipulating Instructions :   
 - BTST - tests a single bit.  
 - BSET - set a single bit.  
 - BCLR - clear a single bit.  
 - BCHG - change a single bit.  

System Control instructions:
 - MOVE USP - Move an operand to user stack pointer.  
 - RESET - Reset external peripherals.  
 - RTE - Return from an exception. 
 - STOP - Stop processing until an exception occurs.  
 - TCHK - Check an operand against boundaries - used to prevent serious software errors. 
 - TRAP - 16 instructions that provide a method for user program to call a supervisor mode program.

This file will probably remain the same in the future however there may be a sequel to it describing the basics of assembly language and it’s use in cracking software.

ProZaq